package cn.jit.ssm.web.controller.support;

import cn.jit.ssm.constant.MultiEnvConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.ContextLoaderListener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;

/**
 * 加载自定义的contextParam
 * @author: Cecurio
 * @create: 2017-12-07 15:23
 **/
public class WebContextListener extends ContextLoaderListener {
    private static final Logger logger = LoggerFactory.getLogger(WebContextListener.class);

    @Override
    public void contextInitialized(ServletContextEvent event) {
        ServletContext context = event.getServletContext();
        String active = context.getInitParameter("spring.profile.active");
        if (MultiEnvConstant.DEV_ENVIRONMENT.equals(active)) {
            logger.info("项目处于开发环境！");
        } else if (MultiEnvConstant.PROD_ENVIRONMENT.equals(active)) {
            logger.info("项目处于生产环境！");
        } else if (MultiEnvConstant.TEST_ENVIRONMENT.equals(active)) {
            logger.info("项目处于测试环境！");
        } else {
            logger.info("项目配置有误！");
        }
    }
}
